package com.ruoyi.web.controller.patient_illness_info;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.patient_illness_info.domain.PatientIllnessInfo;
import com.ruoyi.patient_illness_info.service.IPatientIllnessInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 患者患病信息Controller
 * 
 * @author ruoyi
 * @date 2024-07-07
 */
@RestController
@RequestMapping("/patient_illness_info/info")
public class PatientIllnessInfoController extends BaseController
{
    @Autowired
    private IPatientIllnessInfoService patientIllnessInfoService;


    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatientIllnessInfo patientIllnessInfo)
    {
        startPage();
        List<PatientIllnessInfo> list = patientIllnessInfoService.selectPatientIllnessInfoList(patientIllnessInfo);
        return getDataTable(list);
    }
    //通过patient_idcard来筛选用户 然后再分组
    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:patient_category')")
    @GetMapping("/patient_category")
    public TableDataInfo selectpatientcategorylist(String patient_idcard)
    {

        startPage();
        List<Map<String, Long>> list = patientIllnessInfoService.selectpatientcategorylist(patient_idcard);

        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:export')")
    @Log(title = "患者患病信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientIllnessInfo patientIllnessInfo)
    {
        List<PatientIllnessInfo> list = patientIllnessInfoService.selectPatientIllnessInfoList(patientIllnessInfo);
        ExcelUtil<PatientIllnessInfo> util = new ExcelUtil<PatientIllnessInfo>(PatientIllnessInfo.class);
        util.exportExcel(response, list, "患者患病信息数据");
    }

    /**
     * 获取患者患病信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:query')")
    @GetMapping(value = "/{patientId}")
    public AjaxResult getInfo(@PathVariable("patientId") Long patientId)
    {
        return AjaxResult.success(patientIllnessInfoService.selectPatientIllnessInfoByPatientId(patientId));
    }

    /**
     * 新增患者患病信息
     */
    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:add')")
    @Log(title = "患者患病信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatientIllnessInfo patientIllnessInfo)
    {
        return toAjax(patientIllnessInfoService.insertIllnessInfoAndreducedrug(patientIllnessInfo));
    }

    /**
     * 修改患者患病信息
     */
    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:edit')")
    @Log(title = "患者患病信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatientIllnessInfo patientIllnessInfo)
    {
        return toAjax(patientIllnessInfoService.updatePatientIllnessInfo(patientIllnessInfo));
    }

    /**
     * 删除患者患病信息
     */
    @PreAuthorize("@ss.hasPermi('patient_illness_info:info:remove')")
    @Log(title = "患者患病信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{patientIds}")
    public AjaxResult remove(@PathVariable Long[] patientIds)
    {
        return toAjax(patientIllnessInfoService.deletePatientIllnessInfoByPatientIds(patientIds));
    }
}
